package com.tdam2011.grupo02.messagesender;

import java.util.LinkedList;

import com.tdam2011.grupo02.data.DatabaseHelperSingleton;
import com.tdam2011.grupo02.domain.MensajeWeb;
import com.tdam2011.grupo02.ui.ContactActionControllerSingleton;

import android.app.IntentService;
import android.content.Intent;
import android.util.Log;

public class SendOutboxIntentService extends IntentService {

	private static final String SEND_OUTBOX_INTENT_SERVICE_CLASS_NAME = SendOutboxIntentService.class
			.toString();

	public SendOutboxIntentService() {
		super(SEND_OUTBOX_INTENT_SERVICE_CLASS_NAME);
	}

	@Override
	protected void onHandleIntent(Intent arg0) {
		Log.d("DEMO", "outbox service onHandleIntent");

		LinkedList<MensajeWeb> msgws = DatabaseHelperSingleton
				.getInstance(this).getDatabaseHelper()
				.getMsgwOutboxByContact(null);

		if (msgws != null && !msgws.isEmpty()) {
			Log.d("DEMO", "hay mensajes web para enviar");
			ContactActionControllerSingleton.getInstance(this)
					.getContactActionController().sendMsgWebOutbox(msgws);
		}
	}

}
